// 引入路由组件
import Home from '@/pages/Home';

export default [
  // 首页
  {
    path: '/home',
    component: Home,
    meta: { show: true }
  },
  // 搜索页
  {
    path: '/search/:keyword?',
    component: () => import('@/pages/Search'),
    meta: { show: true },
    name: 'search',
    // 布尔值 params 
    // props:true
    // 对象：额外给路由组件传递一些 props 数据
    // props:{a:1,b:2}
    // 函数：可以 params query 通过 props 传递给路由组件
    // props($route) {
    //   return {keyword:$route.params.keyword,k:$route.query.k}
    // }
  },
  // 登录页
  {
    path: '/login',
    component: () => import('@/pages/Login'),
    meta: { show: false }
  },
  // 注册页
  {
    path: '/register',
    component: () => import('@/pages/Register'),
    meta: { show: false }
  },
  // 产品详情
  {
    path: '/detail/:skuid?',
    component: () => import('@/pages/Detail'),
    meta: { show: true }
  },
  // 加入购物车成功
  {
    path: '/addcartsuccess',
    component: () => import('@/pages/AddCartSuccess'),
    meta: { show: true },
    name: 'addcartsuccess',
  },
  // 购物车页
  {
    path: '/shopcart',
    component: () => import('@/pages/ShopCart'),
    meth: { show: true },

  },
  // 结算页
  {
    path: '/trade',
    component: () => import('@/pages/Trade'),
    meta: { show: true },
    // 路由独享守卫
    beforeEnter: (to, from, next) => {
      // 去交易页面 必须从购物车进入
      if (from.path == "/shopcart") {
        next()
      } else {
        // 其他页面：回到原页面
        next(from.path)
      }
    },
  },
  // 提交订单页
  {
    path: '/pay',
    component: () => import('@/pages/Pay'),
    meta: { show: true },
    beforeEnter: (to, from, next) => {
      if (from.path === '/trade') {
        next()
      } else {
        next(from.path)
      }
    },
  },
  // 支付成功页
  {
    path: '/paysuccess',
    component: () => import('@/pages/PaySuccess'),
    meta: { show: true },
  },
  // 个人中心页
  {
    path: '/center',
    component: () => import('@/pages/Center'),
    meta: { show: true },
    // 子路由组件
    children: [
      // 我的订单二级路由
      {
        path: 'myOrder',
        component: () => import('@/pages/Center/myOrder'),
      },
      // 团购订单二级路由
      {
        path: 'grouporder',
        component: () => import('@/pages/Center/groupOrder')
      },
      {
        path: '/center',
        redirect: '/center/myorder'
      }
    ]
  },
  // 重定向：原本是根，跳转到 home
  {
    path: "/",
    redirect: "/home"
  },
]
